//
//  NavigationController.swift
//  weiboDemo
//
//  Created by zq on 2020/10/27.
//

import UIKit

class NavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏导航条
//        navigationBar.isHidden = true
        //设置导航条的字体的颜色
        navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.darkGray]
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
     
        //只有走了push方法这个viewController才会加到 viewControllers 里面
        if viewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            if let vc = viewController as? BaseViewController {
                var title = "返回"
                if viewControllers.count == 1 { //手动push第一个viewController时
                    title = viewControllers.first?.title ?? "返回"
                }
                vc.navigationItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(pop),isBack:true)
            }
        }
        
        super.pushViewController(viewController, animated: animated)

    }
    
    @objc func pop() -> () {
        popViewController(animated: true)
    }

}
